package com.yanqu.road.server.cmd.activity.recallplayer;

import com.yanqu.road.entity.activity.recallplayer.data.RecallPlayerBeBindTaskValue;
import com.yanqu.road.logic.pb.RecallPlayerPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.RecallPlayerProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.manger.activity.recallplayer.RecallPlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.ArrayList;
import java.util.List;

@Cmd(code = GameProtocol.S_RECALL_PLAYER_SYNC_BIND_TASK, desc = "跨服同步过来绑定玩家的任务值")
public class RecallPlayerReceiveTaskValueCmd implements Command {
    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {
        RecallPlayerProto.SyncBindTaskDataMsg msg = RecallPlayerProto.SyncBindTaskDataMsg.parseFrom(yanQuMessage.getBytes());
        List<RecallPlayerBeBindTaskValue> taskValueList = new ArrayList<>();
        for (RecallPlayerProto.BindTaskInfo bindTaskValue : msg.getTaskInfoList()) {
            RecallPlayerBeBindTaskValue taskValue = RecallPlayerPb.parseToBindTaskValue(bindTaskValue);
            taskValueList.add(taskValue);
        }
        RecallPlayerMgr.UpdateBindTask(msg.getRecallUserId(), msg.getSyncToUserId(), taskValueList);
    }
}
